package com.sicheng.algorithm.dynamic;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/1/28 11:46
 */
public class 跳跃 {
    public static void main(String[] args) {
        int[] nums = {3, 2, 1, 0, 4};
        System.out.println(canJump(nums));

    }

    public static boolean canJump(int[] nums) {
        if (nums.length == 1)
            return true;
        int maxIndex = 0;
        for (int i = 0; i < nums.length; i++) {
            if (i > maxIndex) {
                return false;
            }
            maxIndex = Math.max(maxIndex, nums[i] + i);
            if (maxIndex >= nums.length - 1)
                return true;

        }

        return false;
    }
}
